package com.google.code.virtualhockey.vhx.server.model

import java.util.Date
import com.google.code.virtualhockey.vhx.sds.{STMetaData, STNamedEntity}
import com.google.code.virtualhockey.vhx.sds.fields.{SDate, SShortText}

/**
 * Represents a user that has explicitly registered to participate in the game.
 */
class RegisteredUser( userId: String,
                      var email: String,
                      var pseudonym: String,
                      var country: String,
                      var place: String,
                      val validFrom: Date ) extends STNamedEntity[RegisteredUser] {

  setEntityName( userId )

  /** Private no-arg constructor for SDS. */
  private def this() = this( null, null, null, null, null, null )
}

object RegisteredUserMeta extends STMetaData[RegisteredUser] {
  val cls = classOf[RegisteredUser]
  val kind = "RegisteredUser"
  val fields = List(
    new SShortText( this, "email", true ),
    new SShortText( this, "pseudonym", true ),
    new SShortText( this, "country", false ),
    new SShortText( this, "place", false ),
    new SDate( this, "validFrom", false ) )

  /**
   * Creates a new Club instance from a CSV file line.
   */
  override def fromCsv( values: List[Any] ): RegisteredUser = {
    new RegisteredUser( values(0).toString,
                        values(1).toString,
                        values(2).toString,
                        values(3).toString,
                        values(4).toString,
                        values(5).asInstanceOf[Date] )
  }
}
